package com.ttg.web.controller.common;

import com.ttg.common.entities.BaseResult;
import com.ttg.common.utils.RequestParamsManager;
import com.ttg.model.dto.*;
import com.ttg.model.vo.AdminViewVo;
import com.ttg.web.service.AdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhangjie
 * @date 2021/3/16 14:38
 */
@Slf4j
@Api("机构管理员信息")
@RestController
@RequestMapping("/org1")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @ApiOperation("查看管理员详细资料")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adm_id",required = false,value = "管理员编号",paramType = "form"),
            @ApiImplicitParam(name = "adm_type",required = false,value = "用户类型（1总后台管理员，2运营平台管理员，3代理商）",paramType = "form"),
    })
    @RequestMapping("/admin/view")
    public BaseResult<AdminViewVo> view(@RequestBody(required = false) String data){
        AdminViewDTO reqDto = RequestParamsManager.transformRequestParam(data, AdminViewDTO.class);
        return BaseResult.success(adminService.view(reqDto));
    }
    @ApiOperation("删除管理员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adm_id",required = true,value = "管理员编号",paramType = "form")
    })
    @RequestMapping("/admin/delete")
    public BaseResult delete(@RequestBody(required = false) String data){
        AdminDeleteDTO reqDto = RequestParamsManager.transformRequestParam(data, AdminDeleteDTO.class);
        return BaseResult.success(adminService.delete(reqDto));
    }
    @ApiOperation("修改个人密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adm_id",required = true,value = "管理员编号",paramType = "form"),
            @ApiImplicitParam(name = "password",required = true,value = "新密码",paramType = "form"),
            @ApiImplicitParam(name = "password2",required = true,value = "再次输入密码",paramType = "form"),
            @ApiImplicitParam(name = "old_password",required = true,value = "旧密码",paramType = "form"),
    })
    @RequestMapping("/admin/password")
    public BaseResult password(@RequestBody(required = false) String data){
        AdminPwdDTO reqDto = RequestParamsManager.transformRequestParam(data, AdminPwdDTO.class);
        return BaseResult.success(adminService.password(reqDto));
    }
    @ApiOperation("角色隐藏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role_id",required = true,value = "角色编号",paramType = "form"),
            @ApiImplicitParam(name = "is_hide",required = true,value = "0-显示，1-隐藏",paramType = "form")
    })
    @RequestMapping("/admin/roleStatus")
    public BaseResult roleStatus(@RequestBody(required = false) String data){
        RoleStatusDTO reqDto = RequestParamsManager.transformRequestParam(data, RoleStatusDTO.class);
        return BaseResult.success(adminService.roleStatus(reqDto));
    }
    @ApiOperation("添加角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role_name",required = true,value = "角色名称",paramType = "form"),
            @ApiImplicitParam(name = "role_type",required = true,value = "角色类型（1总公司，2运营平台，3商户，4机构角色）",paramType = "form"),
            @ApiImplicitParam(name = "auth_id",required = true,value = "角色关联的权限列表",paramType = "form"),
            @ApiImplicitParam(name = "role_desc",required = true,value = "角色描述",paramType = "form")
    })
    @RequestMapping("/admin/roleAddsave")
    public BaseResult roleAddsave(@RequestBody(required = false) String data){
        RoleAddSaveDTO reqDto = RequestParamsManager.transformRequestParam(data, RoleAddSaveDTO.class);
        return BaseResult.success(adminService.roleAddsave(reqDto));
    }

    @ApiOperation("修改角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role_id",required = true,value = "角色编号",paramType = "form"),
            @ApiImplicitParam(name = "role_name",required = true,value = "角色名称",paramType = "form"),
            @ApiImplicitParam(name = "role_type",required = true,value = "角色类型（1总公司，2运营平台，3商户，4机构角色）",paramType = "form"),
            @ApiImplicitParam(name = "auth_id",required = true,value = "角色关联的权限列表",paramType = "form"),
            @ApiImplicitParam(name = "role_desc",required = true,value = "角色描述",paramType = "form")
    })
    @RequestMapping("/admin/roleEditsave")
    public BaseResult roleEditsave(@RequestBody(required = false) String data){
        RoleEditsaveDTO reqDto = RequestParamsManager.transformRequestParam(data, RoleEditsaveDTO.class);
        return BaseResult.success(adminService.roleEditsave(reqDto));
    }

    @ApiOperation("删除角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role_id",required = true,value = "角色编号",paramType = "form")
    })
    @RequestMapping("/admin/roleDelete")
    public BaseResult roleDelete(@RequestBody(required = false) String data){
        RoleDeleteDTO reqDto = RequestParamsManager.transformRequestParam(data, RoleDeleteDTO.class);
        return BaseResult.success(adminService.roleDelete(reqDto));
    }

    @ApiOperation("获取角色列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword",value = "关键字(角色名称，角色id)",paramType = "form"),
            @ApiImplicitParam(name = "role_type",value = "角色类型（1总公司，2运营平台，3商户，4机构角色）",paramType = "form"),
    })
    @RequestMapping("/admin/roleList")
    public BaseResult roleList(@RequestBody(required = false) String data){
        RoleListDTO reqDto = RequestParamsManager.transformRequestParam(data, RoleListDTO.class);
        return BaseResult.success(adminService.roleList(reqDto));
    }

    @ApiOperation("获取频道及权限")
    @RequestMapping("/admin/roleAuth")
    public BaseResult roleAuth(){
        return BaseResult.success(adminService.roleAuth());
    }

    @ApiOperation("角色明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role_id",required = true,value = "角色编号",paramType = "form")
    })
    @RequestMapping("/admin/roleView")
    public BaseResult roleView(@RequestBody(required = false) String data){
        RoleViewDTO reqDto = RequestParamsManager.transformRequestParam(data, RoleViewDTO.class);
        return BaseResult.success(adminService.roleView(reqDto));
    }

    @ApiOperation("管理员列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status",value = "用户状态（1有效，2锁定，4删除）",paramType = "form"),
            @ApiImplicitParam(name = "trueName",value = "真实姓名",paramType = "form"),
            @ApiImplicitParam(name = "userName",value = "用户账号",paramType = "form"),
            @ApiImplicitParam(name = "admId",value = "编号",paramType = "form")
    })
    @RequestMapping("/admin/index")
    public BaseResult index(@RequestBody(required = false) String data){
        AdminIndexDTO reqDto = RequestParamsManager.transformRequestParam(data, AdminIndexDTO.class);
        return BaseResult.success(adminService.index(reqDto));
    }

    @ApiOperation("获取角色")
    @RequestMapping("/admin/role")
    public BaseResult role(){
        return BaseResult.success(adminService.role());
    }

    @ApiOperation("添加管理员数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adm_user_name",value = "用户登录名",required = true,paramType = "form"),
            @ApiImplicitParam(name = "adm_true_name",value = "真实姓名",required = true,paramType = "form"),
            @ApiImplicitParam(name = "adm_password",value = "密码",required = true,paramType = "form"),
            @ApiImplicitParam(name = "status",value = "用户状态（1有效，2锁定，4删除）",required = true,paramType = "form"),
            @ApiImplicitParam(name = "roles",value = "管理角色",required = true,paramType = "form"),
            @ApiImplicitParam(name = "adm_mobile",value = "管理员手机",paramType = "form"),
            @ApiImplicitParam(name = "adm_email",value = "管理员邮箱",paramType = "form")
    })
    @RequestMapping("/admin/addSave")
    public BaseResult addSave(@RequestBody(required = false) String data){
        AdminAddSaveDTO reqDto = RequestParamsManager.transformRequestParam(data, AdminAddSaveDTO.class);
        return BaseResult.success(adminService.addSave(reqDto));
    }

    @ApiOperation("修改管理员数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adm_id",value = "管理员Id",required = true,paramType = "form"),
            @ApiImplicitParam(name = "adm_true_name",value = "真实姓名",required = true,paramType = "form"),
            @ApiImplicitParam(name = "roles",value = "管理角色列表",required = true,paramType = "form"),
            @ApiImplicitParam(name = "adm_password",value = "密码",required = true,paramType = "form"),
            @ApiImplicitParam(name = "status",value = "用户状态（1有效，2锁定，4删除）",required = true,paramType = "form"),
            @ApiImplicitParam(name = "adm_mobile",value = "管理员手机",paramType = "form"),
            @ApiImplicitParam(name = "adm_email",value = "管理员邮箱",paramType = "form")
    })
    @RequestMapping("/admin/editSave")
    public BaseResult editSave(@RequestBody(required = false) String data){
        AdminEditSaveDTO reqDto = RequestParamsManager.transformRequestParam(data, AdminEditSaveDTO.class);
        return BaseResult.success(adminService.editSave(reqDto));
    }

    @ApiOperation("管理员日志")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adm_id",value = "管理员Id",required = true,paramType = "form"),
            @ApiImplicitParam(name = "user_name",value = "用户登录姓名",required = true,paramType = "form"),
            @ApiImplicitParam(name = "true_name",value = "用户真实姓名",required = true,paramType = "form"),
            @ApiImplicitParam(name = "obj_id",value = "操作对象编号",required = true,paramType = "form"),
            @ApiImplicitParam(name = "keyword",value = "频道名称",paramType = "form"),
            @ApiImplicitParam(name = "sdate",value = "操作时间范围",paramType = "form"),
            @ApiImplicitParam(name = "edate",value = "操作时间范围",paramType = "form")
    })
    @RequestMapping("/admin/log")
    public BaseResult log(@RequestBody(required = false) String data){
        ManageAdminLogDTO reqDto = RequestParamsManager.transformRequestParam(data, ManageAdminLogDTO.class);
        return BaseResult.success(adminService.log(reqDto));
    }

}
